<?php
/**
 * Product Admin List View
 * 
 * This is the product list. This file is a good example of how we'll be listing things in the admin. I want
 * to list all objects in a similar way so that everything has the same basic feel. This way if you know how
 * to use one list screen, you can use them all (for the most part).
 * 
 * @todo I need to build my own $this->url() helper which will also take GET parameters. Right now I'm doing
 * it all manually. It would be very nice to be able to specify GET params as an array. I also think I might
 * like to change the order of url() to have the route name first, instead of the param array. Another thing
 * that would be useful is the ability to specify an array of parameters to use for the entire page's links.
 * This way you could specify order, direction, etc. at the top of the page, and all links would automatically
 * know to use these values unless otherwise specified.
 */
?>
<div class="header">
	<h2>Product Admin</h2>
	<div class="add">
		<a href="<?= $this->routeUrl("admin_product_add") ?>">Create New Product</a>
	</div>
	<div style="clear:both"></div>
</div>
<div id="productadmin">
	<table class="admin">
		<thead>
			<tr>
				<?php // @todo This needs to use the get params in routeUrl ?>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'product_id', 'dir' => $this->dir)) ?>">ID</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'title', 'dir' => $this->dir)) ?>">Product</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'cost', 'dir' => $this->dir)) ?>">Cost</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'price', 'dir' => $this->dir)) ?>">Price</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'weight', 'dir' => $this->dir)) ?>">Weight</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'sku', 'dir' => $this->dir)) ?>">SKU</a></th>
				<th><a href="<?= $this->routeUrl("admin_product_list", null, array('order' => 'upc', 'dir' => $this->dir)) ?>">UPC</a></th>
				<th> &nbsp; </th>
			</tr>
		</thead>
		<tbody>
			<?php foreach ($this->products as $product): ?>
				<tr class="product <?= $this->cycle(array("odd", "even"))->next() ?>">
					<th class="product_id"><?= $this->e($product['product_id']) ?></th>
					<td class="title"><a href="<?= $this->routeUrl("admin_product_edit", array('product_id' => $product['product_id'])) ?>"><?= $this->e($product['title']) ?></a></td>
					<td class="cost"><?= $this->e($product['cost']) ?></td>
					<td class="price"><?= $this->e($product['price']) ?></td>
					<td class="weight"><?= $this->e($product['weight']) ?></td>
					<td class="sku"><?= $this->e($product['sku']) ?></td>
					<td class="upc"><?= $this->e($product['upc']) ?></td>
					<td class="admin">
						<a href="<?= $this->routeUrl("admin_product_edit", array('product_id' => $product['product_id'])) ?>">Edit</a>&nbsp;|&nbsp;
						<a href="<?= $this->routeUrl("admin_product_delete", array('product_id' => $product['product_id'])) ?>" onclick="return confirm('Are you sure you want to delete this product?')">Delete</a>
					</td>
				</tr>
			<?php endforeach ?>
		</tbody>
	</table>
	
	<?= $this->paginationControl($this->products) ?>

</div> <!-- /#productadmin -->